<!DOCTYPE html>
<!-- saved from url=(0056)http://startbootstrap.com/templates/simple-sidebar.html# -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>Panel</title>
<script src="<?php echo base_url();?>js/chart.js"></script>
<?php $this->load->view('panel_head');?>
</head>

<body onload="startTime()">

<script>
	function _(el){
		return document.getElementById(el);
	}
	
	function uploadFile(){
		
	}
	
	function progressHandler(event){
		_("message").innerHTML = "<progress id='progressBar' value='0' max='100' style='width:300px;'></progress>";
		_("loaded_n_total").innerHTML = "Uploaded "+event.loaded+" bytes of "+event.total;
		var percent = (event.loaded / event.total) * 100;
		_("progressBar").value = Math.round(percent);
		_("progressBar").width = Math.round(percent)+'px';
		_("status").innerHTML = Math.round(percent)+"% uploaded... please wait";
	}
	
	function completeHandler(event){
		//_("status").innerHTML = event.target.responseText;
		//_("progressBar").value = 0;
	}
	
	function errorHandler(event){
		_("status").innerHTML = "Upload Failed";
	}
	
	function abortHandler(event){
		_("status").innerHTML = "Upload Aborted";
	}
</script>

<script language="javascript">
		
	function chk()
	{			
		var pro = 0;
		var fty=new Array(".flv",".FLV",".mp3",".MP3",".mp4",".MP4",".f4v",".F4V",".m4v",".M4V"); // ประเภทไฟล์ที่อนุญาตให้อัพโหลด   
			var a=document.form1.file_1.value; //กำหนดค่าของไฟล์ใหกับตัวแปร a   
			var permiss=0; // เงื่อนไขไฟล์อนุญาต
			a=a.toLowerCase();   
			if(a !=""){
				for(i=0;i<fty.length;i++){ // วน Loop ตรวจสอบไฟล์ที่อนุญาต   
					if(a.lastIndexOf(fty[i])>=0){  // เงื่อนไขไฟล์ที่อนุญาต   
						permiss=1;
						break;
					}else{
						continue;
					}
				}  
				if(permiss==0){ 
					alert("Upload only FLV ,MP3 ,MP4 ,F4V and M4V format ");   
					document.getElementById("file_1").focus();  									
					return false;   			
				} else {
					var file = _("file_1").files[0];
					//alert(file.name+" | "+file.size+" | "+file.type);
					var formdata = new FormData();
					formdata.append("file_1", file);
					var ajax = new XMLHttpRequest();
					ajax.upload.addEventListener("progress", progressHandler, false);
					ajax.addEventListener("load", completeHandler, false);
					ajax.addEventListener("error", errorHandler, false);
					ajax.addEventListener("abort", abortHandler, false);
					ajax.open("POST", "<?php echo base_url();?>index.php/upload/upload_vdo");
					ajax.send(formdata);		
								
				}
			}
	
	}
</script>

<?php $this->load->view('panel_header');?>
<div style="height:46px;"></div>
<div id="wrapper"> 
  
  <!-- Sidebar -->
  <div id="sidebar-wrapper">
    <?php $this->load->view('panel_sidebar');?>
  </div>
  
  <!-- Page content -->
  <div id="page-content-wrapper">
    <div class="content-header">
      <h1><span class="glyphicon glyphicon-film"></span>&nbsp;Upload</h1>
    </div>
    <!-- Keep all page content within the page-content inset div! -->
    
    <div class="page-content inset">
    
    <div align="center">
    <div><font size="+6"><span class="glyphicon glyphicon-cloud-upload"></span></font></div>
    <div><h3>Select files to upload</h3></div>
    
    <div style="margin-top:1.5em;">
    	<?php $attributes = array('onsubmit' => 'return chk()', 'id' => 'form1' ,'name' => 'form1'); ?>
    	<?php echo form_open_multipart('upload/upload_vdo' ,$attributes);?>
    	
  		<input type="file" name="file" id="file_1" required/>   
        <div style="padding:1em 0em 1em; width:20em;"> 
        <select class="form-control" name="select_server">
        	<?php foreach($server as $server_2) { ?>
           		 <option value="<?php echo $server_2['server_id']; ?>"><?php echo $server_2['server_name'];?> (<?php echo $server_2['server_ip'];?>)</option>
            <?php } ?>          
        </select>
        
        
        </div>
        
        
        <!--
        <div style="width:6em; margin-bottom:1em;"> 
        <select class="form-control" name="vdo_status">
          <option value="0">Public</option>
          <option value="1">Private</option>
        </select>
        </div>
        -->
        
    </div>
 			            
              <div id="message"></div>
              <h3 id="status"></h3>
              <p id="loaded_n_total"></p>
              
   			   <input type="submit" name="Submit" value="Upload now" onclick="uploadFile()"/>
   
      
          
  
   

<?php echo form_close();?>
</br></br>
<?php if($this->uri->segment(3) == 'error' ) { ?>
<h4><strong><font color="#ff0000">File Upload Failed !!</font></strong></h4>
<?php } ?>
    
    </div>
   
       
    </div>
    <!-- <div class="page-content inset"> --> 
    
  </div>
  <!--  <div id="page-content-wrapper"> --> 
  
</div>
<!-- <div id="wrapper"> --> 


<!-- Custom JavaScript for the Menu Toggle --> 
<script>
    $("#menu-toggle").click(function(e) {
        e.preventDefault();
        $("#wrapper").toggleClass("active");
    });
</script> 

<!-- checkbox --> 
<script>
$('#select-all').click(function(event) {   
    if(this.checked) {
        // Iterate each checkbox
        $(':checkbox').each(function() {
            this.checked = true;                        
        });
    }else{
		$(':checkbox').each(function() {
			this.checked = false;
		});
	}
});
</script>
</body>
</html>